package Server; //done

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * This class controls the connection to MySQL DataBase.
 * @author waleed
 * @author kamil
 */
public class ConnectionTOmysql{
	
	/** The MySQL connection. */
	private Connection connection;
	
	/** The user name. */
	private static String username = "";
	
	/** The user password. */
	private static String password = "";
	
	/** The DataBase name. */
	private static String DB_Name = "";
	
	/**
	 * Default Constructor
	 */
	public ConnectionTOmysql(){
		try{
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		} 
		catch (Exception ex) {
		}
    
		try {
			connection = DriverManager.getConnection("jdbc:mysql://localhost/"+DB_Name,username,password);
		} 
		catch (SQLException ex) {
			System.out.println("SQLException: " + ex.getMessage());
			System.out.println("SQLState: " + ex.getSQLState());
			System.out.println("VendorError: " + ex.getErrorCode());
        }
	}

	/**
	 * Connection getter
	 * @return the Connection
	 */
	public Connection getConnection() {
		return connection;
	}

	/**
	 * password getter
	 * @return the password
	 */
	public static String getPassword() {
		return password;
	}

	/**
	 * password setter
	 * @param password the password to set
	 */
	public static void setPassword(String password) {
		ConnectionTOmysql.password = password;
	}

	/**
	 * User Name getter
	 * @return the username
	 */
	public static String getUsername() {
		return username;
	}

	/**
	 * User Name setter
	 * @param username the user name to set
	 */
	public static void setUsername(String username) {
		ConnectionTOmysql.username = username;
	}
	
	/**
	 * DB Name getter
	 * @return the DataBase Name
	 */
	public static String getDB_Name() {
		return DB_Name;
	}

	/**
	 * DB Name setter
	 * @param DB_Name The DataBase name to set
	 */
	public static void setDB_Name(String DB_Name) {
		ConnectionTOmysql.DB_Name = DB_Name;
	}
}
